// Copyright 2020 Real-Time Innovations, Inc. (RTI)
//
// Copyleft 2024, Black Sesame Technologies
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef DAL_CONNEXTDDS__LOG_HPP_
#define DAL_CONNEXTDDS__LOG_HPP_

#include "dal_connextdds/static_config.hpp"

// #include "dcutils/logging_macros.h"


#if DAL_CONNEXT_LOG_MODE == DAL_CONNEXT_LOG_MODE_ALL

#define DAL_CONNEXT_LOG_ERROR(msg_)

#define DAL_CONNEXT_LOG_ERROR_A(fmt_, ...)

#define DAL_CONNEXT_LOG_WARNING(msg_)

#define DAL_CONNEXT_LOG_WARNING_A(fmt_, ...)

#define DAL_CONNEXT_LOG_INFO(msg_)

#define DAL_CONNEXT_LOG_INFO_A(fmt_, ...)

#define DAL_CONNEXT_LOG_DEBUG(msg_)

#define DAL_CONNEXT_LOG_DEBUG_A(fmt_, ...)

#define DAL_CONNEXT_LOG_TRACE(msg_)

#define DAL_CONNEXT_LOG_TRACE_A(fmt_, ...)

#elif DAL_CONNEXT_LOG_MODE == DAL_CONNEXT_LOG_MODE_PRINTF

#include <stdio.h>

#define DAL_CONNEXT_LOG_ERROR_A(fmt_, ...)
  printf("[ERROR][%s] " fmt_ "\n", DAL_CONNEXTDDS_ID, __VA_ARGS__);

#define DAL_CONNEXT_LOG_ERROR(msg_)
  printf("[ERROR][%s] %s\n", DAL_CONNEXTDDS_ID, (msg_));

#define DAL_CONNEXT_LOG_WARNING_A(fmt_, ...)
  printf("[WARNING][%s] " fmt_ "\n", DAL_CONNEXTDDS_ID, __VA_ARGS__);

#define DAL_CONNEXT_LOG_WARNING(msg_)
  printf("[WARNING][%s] %s\n", DAL_CONNEXTDDS_ID, (msg_));

#define DAL_CONNEXT_LOG_DEBUG_A(fmt_, ...)
  printf("[DEBUG][%s] " fmt_ "\n", DAL_CONNEXTDDS_ID, __VA_ARGS__);

#define DAL_CONNEXT_LOG_DEBUG(msg_)
  printf("[DEBUG][%s] %s\n", DAL_CONNEXTDDS_ID, (msg_));

#define DAL_CONNEXT_LOG_INFO_A(fmt_, ...)
  printf("[INFO][%s] " fmt_ "\n", DAL_CONNEXTDDS_ID, __VA_ARGS__);

#define DAL_CONNEXT_LOG_INFO(msg_)
  printf("[INFO][%s] %s\n", DAL_CONNEXTDDS_ID, (msg_));

#define DAL_CONNEXT_LOG_TRACE(msg_)

#define DAL_CONNEXT_LOG_TRACE_A(fmt_, ...)

#elif DAL_CONNEXT_LOG_MODE == DAL_CONNEXT_LOG_MODE_DEFAULT

#define DAL_CONNEXT_LOG_ERROR(msg_)

#define DAL_CONNEXT_LOG_ERROR_A(fmt_, ...)

#define DAL_CONNEXT_LOG_WARNING(msg_)

#define DAL_CONNEXT_LOG_WARNING_A(fmt_, ...)

#define DAL_CONNEXT_LOG_INFO(msg_)

#define DAL_CONNEXT_LOG_INFO_A(fmt_, ...)

#define DAL_CONNEXT_LOG_DEBUG(msg_)

#define DAL_CONNEXT_LOG_DEBUG_A(fmt_, ...)

#define DAL_CONNEXT_LOG_TRACE(msg_)

#define DAL_CONNEXT_LOG_TRACE_A(fmt_, ...)

#else

#define DAL_CONNEXT_LOG_ERROR(msg_)

#define DAL_CONNEXT_LOG_ERROR_A(fmt_, ...)

#define DAL_CONNEXT_LOG_WARNING(msg_)

#define DAL_CONNEXT_LOG_WARNING_A(fmt_, ...)

#define DAL_CONNEXT_LOG_DEBUG(msg_)

#define DAL_CONNEXT_LOG_DEBUG_A(fmt_, ...)

#define DAL_CONNEXT_LOG_INFO(msg_)

#define DAL_CONNEXT_LOG_INFO_A(fmt_, ...)

#define DAL_CONNEXT_LOG_TRACE(msg_)

#define DAL_CONNEXT_LOG_TRACE_A(fmt_, ...)

#endif

#define DAL_CONNEXT_LOG_NOT_IMPLEMENTED
  DAL_CONNEXT_LOG_ERROR_A("%s: not implemented", __func__)


#if DAL_CONNEXT_ASSERT_ENABLE
#include <cassert>

#define DAL_CONNEXT_ASSERT(cond)
  assert(cond);

#else

#define DAL_CONNEXT_ASSERT(cond)

#endif /* DAL_CONNEXT_ASSERT_ENABLE */

#define DAL_CONNEXT_LOG_ERROR_SET(msg_)

#define DAL_CONNEXT_LOG_ERROR_A_SET(fmt_, ...)

#endif  // DAL_CONNEXTDDS__LOG_HPP_
